
var ECharts = function(classPath,divId,url) {
	this.classPath = classPath;
	this.url = url;
	this.divId = divId;
	this.data = "";
	this.param = "none";
	if(this.url == undefined){
		this.url = this.getRootPath()+"/ReportService";
	}
};

ECharts.prototype = {
	
	/**
	 * 后台提交数据方法
	 */
	post:function(echarts){
		
		$.ajax({
            type: "POST",
            url: this.url,
            processData: false,
            async: false,
            data: "classPath="+this.classPath+"&chartsType=echarts&param="+this.param ,
            dataType: 'text', 
            success: function(data) {
            	echarts.data = data;
            }
        });
		
	},
	
	/**
	 * 获取根路径
	 * @returns
	 */
	getRootPath:function(){
		
	    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
	    var curWwwPath=window.document.location.href;
	    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
	    var pathName=window.document.location.pathname;
	    var pos=curWwwPath.indexOf(pathName);
	    //获取主机地址，如： http://localhost:8083
	    var localhostPaht=curWwwPath.substring(0,pos);
	    //获取带"/"的项目名，如：/uimcardprj
	    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
	    return(localhostPaht+projectName);
		
	},
	
	/**
	 * 页面加载方法
	 */
	pageOn:function(echarts){
		
		var myChart = echarts.init(document.getElementById(this.divId)); 
		
		this.post(this);
		
		eval(this.data);

		myChart.setOption(option,true);	
		
    },
	
    /**
     * 设置参数
     */
	setParam:function(param){
		this.param = param;
	}

};


